<template>
  <el-dialog title="角色" :visible="isShowDialog" @close="closeFn">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">{{ role.name }}</el-checkbox>
    </el-checkbox-group>

    <template #footer>
      <el-row type="flex" justify="center">
        <el-button size="small" type="primary" @click="btnOK">确定</el-button>
        <el-button size="small" @click="closeFn">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { getCompanyRole } from '@/api/compamySetting'
import { getUserDetail } from '@/api/user'
import { assignRoles } from '@/api/employee'

export default {
  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      roleList: [],
      userId: ''
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    // 点击确认 分配角色
    async btnOK() {
      await assignRoles({ id: this.userId, roleIds: this.checkList })
      this.$emit('update:isShowDialog', false)
      this.$message.success('分配成功')
    },
    // 获取用户信息，回显数据
    async  getUserInfo(id) {
      this.userId = id
      const { roleIds } = await getUserDetail(id)
      this.checkList = roleIds
    },
    closeFn() {
      this.$emit('update:isShowDialog', false)
    },
    async getRoleList() {
      const { rows } = await getCompanyRole()
      this.roleList = rows
    }
  }
}
</script>

<style>

</style>
